Title: How to save space with dpkg
Date: 2016-08-24 09:26
Category: debian
Tags: CLI, debian, linux, unix, dpkg, ncdu, du


<sub>This will be a quick post. While the subject is simple it seemed worth sharing... As it was new information to me.</sub>


###OCD: Obsessively Cleaning your Directories
Some of you out there work on minimal setups (ie: low disk space, embedded, etc).
Others of you likely get annoyed by wasted disk space.
I'm just going to assume you fall in both categories, as you read my blog and must be an awesome person. :D <sub>(lets see if my copy editors let me keep this informal tone)</sup>

Personally, I get annoyed at useless large disk usage.
House cleaning my filesystem also has the benefit of speeding up [My Backups].

I had been staring at my `/usr/share/doc/texlive-doc/` for a while, when running `ncdu` to check on my disk usage.
It was just *there*, taking up a gigabyte or so.

    :::bash
    ~ -> du -hcs /usr/share/doc/texlive-doc/
    1.1G    /usr/share/doc/texlive-doc/
    1.1G    total

I have yet to ever read the `TeX` documentation... And I'm not sure if I ever will have the motivation <sup>(ie: a fancy project)</sup> to do so.
After a number of months of staring at the disk usage, I finally decided to figure out how to free it up.


###Your Daily Dose of the Esoteric and Arcane: dpkg
While this may not be the most outlandish, this is a reoccurring theme with my computer knowledge; perhaps it will be one with my blog as well. *wink*

In my research on the proper way to deal with this issue on debian sid, I found that `dpkg` has the ability to exclude and include paths from being installed.
Meet my new friends `path-exclude` and `path-include`.
The use of these is as simple as adding a config to `/etc/dpkg/dpkg.cfg.d/`.  

**Note:** The order of your lines matters, as the later a line the higher priority it has over the previous lines.


###The Config File
`/etc/dpkg/dpkg.cfg.d/excludes`

    :::bash
    ## Drop locales except english and japanese
    path-exclude=/usr/share/locale/*
    path-include=/usr/share/locale/en/*
    path-include=/usr/share/locale/en_US/*
    path-include=/usr/share/locale/ja/*
    path-include=/usr/share/locale/locale.alias

    ## Drop translated manual pages except english and japanese
    path-exclude=/usr/share/man/*
    path-include=/usr/share/man/man[1-9]/*
    path-include=/usr/share/man/en*/*
    path-include=/usr/share/man/ja*/*

    ## Drop annoyingly large texlive-doc
    path-exclude=/usr/share/doc/texlive-doc/*

[My Config File]

This saves me over a gigabyte of space from unused man pages, locales, and of course texlive-doc.
Disk space saving isn't immediate, every time you install or upgrade a package the rules get evaluated and the excludes happen.
Here I allow English and Japanese to install, one of these days I might actually learn the latter.  

**Note:** If you need immediate relief, you have two options.

1. Reinstall all packages.
    * This is likely to have a few issues, at least on sid.
2. Carefully `rm` directories and files.
    * Do so at your own risk, reading my blog comes with ***no warranties!***


###Links
[My Backups]  
[My Config File]  


[My Backups]: {filename}006-backups_options_and_effort.md
[My Config File]: https://notabug.org/demure/dotfiles/src/master/system_wide/etc/dpgk/dpkg.cfg.d/excludes

